package com.foreknow.oppTest1;

import java.util.Scanner;

/**
 * @author shkstart
 * @create 2021-07-23 15:42
 */
public class Game {
    int userscort=0;//得分
    int comscort=0;
    String username;
    String comname;
    Computer computer=new Computer();
    Scanner sc=new Scanner(System.in);

    /**
     * 游戏初始化
     */
    public void initial(){
        System.out.println("请选择对方角色(1:刘备 2：孙权 3：曹操)");
        int key = sc.nextInt();
        System.out.println("请输入你的姓名");
         username = sc.next();
         comname=computer.figure[key-1];
        System.out.println(username+" VS "+comname +"   对战");

    }

    /**
     * 开始游戏
     */
    public void startGame(){
        boolean flag=true;
        while (flag){
            System.out.println("要开始吗？(y/n)");
            String isstart=sc.next();
            char start=isstart.charAt(0);
            if(start=='y'){
                flag=false;
            }else if(start=='n'){
                System.exit(0);
            }else{
                System.out.println("输入错误请重新输入");

            }

            User user=new User();
            int u=user.showFirst();
            int c=computer.showFirst();
/*
*   1 剪刀  2 石头  3 布
 */
            if(u-c==-1||u-c==2){
                System.out.println("你输了  真笨");
                comscort++;

            }else if(u==c){
                System.out.println("平局");
            }else if(u-c==1||u-c==-2){
                System.out.println("你赢了");
                userscort++;
            }


            System.out.println("是否开始下一轮(y/n)");
            String isgoon=sc.next();
            char goon=isgoon.charAt(0);
            if(goon=='y'){
                flag=true;
            }else if(goon=='n'){
                System.out.println("姓名"+"\t"+"得分");
                System.out.println(username+"\t"+ userscort);
                System.out.println(comname+"\t"+ +comscort);
                if(userscort>comscort){
                    System.out.println("你最终获得胜利");
                }else if(userscort>comscort){
                    System.out.println("你最终失败");
                }else {
                    System.out.println("最后平局");
                }
                System.exit(0);
            }else{
                System.out.println("输入错误请重新输入");
                flag=true;
            }
        }
    }
}
